package org.cuit.seon.core.data;

import lombok.Data;
import lombok.NoArgsConstructor;


/**
 * @author EtyMx
 * @date 2021/4/21
 */
@NoArgsConstructor
@Data
public class R<T> {

    /**
     * 状态码
     */
    private int code;

    /**
     * 错误信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    private R(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> R<T> ok(T data) {
        R<T> r = new R<>(200, RMessage.OK);
        r.data = data;
        return r;
    }

    public static <T> R<T> ok() {
        return new R<>(200, RMessage.OK);
    }

    public static <T> R<T> error(int code, String message) {
        return new R<>(code, message);
    }

    public static <T> R<T> error(String message) {
        return R.error(500, message);
    }
}

